<template>
	<view class="page">
		<view class="bar_info" :style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx'}">
			<view class="title_bar">
				<view class="title_bar_left" @tap.stop="isBack">
					<u-icon size="38" color="#000" name="arrow-left"></u-icon>
				</view>
				<view class="title_bar_center">
					<text>立即支付</text>
				</view>
				<view class="title_bar_right"></view>
			</view>
		</view>
		<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
		<view class="info">
			<view class="info_title">实际金额</view>
			<view class="info_money">
				<text class="info_money_1">￥</text>
				<text class="info_money_2">{{Number(order_info.price)}}</text>
			</view>
			<view class="select_title">选择支付方式</view>
			<view class="select_pay">
				<view class="select_pay_left">
					<image src="./static/4.png" mode=""></image>
					<text>微信支付</text>
				</view>
				<view class="select_pay_right">
					<image src="./static/5.png" mode=""></image>
				</view>
			</view>
			<view class="pay_btn" @tap.stop="getBuyMember">立即支付</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_info: {},
			}
		},
		onLoad() {
			this.order_info = uni.getStorageSync('order_info');
			// console.log(this.order_info);
		},
		onShow() {
			
		},
		methods: {
			getBuyMember() {
				this.$api.post(global.apiUrls.postBuyVip, {
					vip_level_id: this.order_info.id
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						this.payVip(res.data.data.order_sn);
					} else {
						this.$message.info(res.data.msg);
					}
				})
				
			},
			// 会员订单支付  postOrderPay
			payVip(order_sn) {
				let _this = this;
				_this.$api.post(global.apiUrls.postOrderPay, {
					order_sn: order_sn,
					order_type: 'vip',
					pay_way: 'wxmini'
				}).then(res => {
					console.log(res);
					if (res.data.code == 1) {
						// 小程序支付
						uni.requestPayment({
							provider: 'wxpay',
							// orderInfo: res.data.data, //微信、支付宝订单数据
							timeStamp: res.data.data.timeStamp,
							nonceStr: res.data.data.nonceStr,
							package: res.data.data.package,
							signType: res.data.data.signType,
							paySign: res.data.data.paySign,
							success: function(res) {
								// console.log(res)
								_this.$message.info('支付成功');
								setTimeout(() => {
									uni.redirectTo({
										url: '/pages/index/buy_success'
									})
								}, 800)
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
								_this.$message.info('支付已取消');
							}
						})
					} else {
						_this.$message.info(res.data.msg);
					}
				})
			},
			
			
			
			isBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}
	.page {
		background-color: #fff;
		.bar_info {
			width: 750rpx;
			height: 88rpx;
			overflow: hidden;
			// border-bottom: 1px solid #eee;
			background: #fff;
			z-index: 10;
			position: fixed;
			top: 0rpx;
		
			.title_bar {
				padding: 0 32rpx;
				display: flex;
				justify-content: space-between;
		
				.title_bar_left {
					width: 50rpx;
					display: flex;
					align-items: center;
				}
		
				.title_bar_center {
					line-height: 88rpx;
					font-size: 36rpx;
					font-weight: 400;
				}
		
				.title_bar_right {
					width: 50rpx;
				}
			}
		}
		.info {
			padding-top: 100rpx;
			.info_title {
				text-align: center;
				margin-bottom: 38rpx;
			}
			.info_money {
				text-align: center;
				.info_money_1 {
					font-size: 44rpx;
					font-weight: 400;
				}
				.info_money_2 {
					font-size: 82rpx;
					font-weight: 400;
				}
			}
			.select_title {
				font-size: 26rpx;
				margin: 128rpx 0 48rpx;
				padding: 0 40rpx;
			}
			.select_pay {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 0 40rpx;
				.select_pay_left {
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 30rpx;
					image {
						width: 40rpx;
						height: 40rpx;
						margin-right: 24rpx;
					}
				}
				.select_pay_right {
					display: flex;
					align-items: center;
					justify-content: center;
					image {
						width: 40rpx;
						height: 40rpx;
					}
				}
			}
			.pay_btn {
				width: 610rpx;
				height: 100rpx;
				background: #0278FC;
				border-radius: 22rpx;
				font-size: 32rpx;
				color: #fff;
				line-height: 100rpx;
				text-align: center;
				position: fixed;
				left: 70rpx;
				bottom: 150rpx;
			}
		}
	}
</style>